﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

namespace Packaging
{
	// Token: 0x02000007 RID: 7
	public class SajetCommon
	{
		// Token: 0x06000025 RID: 37 RVA: 0x00008CD8 File Offset: 0x00006ED8
		public static DialogResult Show_Message(string sKeyMsg, int iType)
		{
			string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(SajetCommon.g_sFileName);
			return ClientUtils.ShowMessage(sKeyMsg, iType, SajetCommon.g_sExeName, fileNameWithoutExtension);
		}

		// Token: 0x06000026 RID: 38 RVA: 0x00008D04 File Offset: 0x00006F04
		public static void AutoCompleteFunction(string AutoCompleteKeys, string DBTable, TextBox txt)
		{
			txt.AutoCompleteSource = AutoCompleteSource.CustomSource;
			txt.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
			txt.AutoCompleteCustomSource.Clear();
			string sSQL = "SELECT " + AutoCompleteKeys + " FROM " + DBTable;
			DataSet dataSet = ClientUtils.ExecuteSQL(sSQL);
			bool flag = dataSet.Tables[0].Rows.Count > 0;
			if (flag)
			{
				for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
				{
					txt.AutoCompleteCustomSource.Add(dataSet.Tables[0].Rows[i][0].ToString());
				}
			}
		}

		// Token: 0x06000027 RID: 39 RVA: 0x00008DBC File Offset: 0x00006FBC
		public static string SNGetNextValue(string StrBarcodeUniqueID, string StrCodeRuleCode, object[][] Params, int state)
		{
			string result;
			try
			{
				string text = "";
				bool flag = string.IsNullOrWhiteSpace(StrBarcodeUniqueID) || string.IsNullOrWhiteSpace(StrCodeRuleCode);
				if (flag)
				{
					SajetCommon.Show_Message("请保证传入参数的完整", 0);
					result = "";
				}
				else
				{
					object[][] @params = new object[][]
					{
						new object[]
						{
							ParameterDirection.Input,
							OracleType.VarChar,
							"barCodeRuleCode",
							StrCodeRuleCode
						}
					};
					string sSQL = "select SBP.* from SAJET.SYS_BARCODERULEPARA SBP,SAJET.SYS_BARCODERULE SB WHERE  SB.BARCODERULE_ID=SBP.BARCODERULE_ID  AND SB.BARCODERULE_CODE=:barCodeRuleCode   ORDER BY BCRP_INDEX  ";
					DataSet dataSet = ClientUtils.ExecuteSQL(sSQL, @params);
					bool flag2 = dataSet != null && dataSet.Tables.Count > 0 && dataSet.Tables[0].Rows.Count > 0;
					if (flag2)
					{
						foreach (object obj in dataSet.Tables[0].Rows)
						{
							DataRow dataRow = (DataRow)obj;
							bool flag3 = dataRow["BCRP_TIMEPARTFORMAT"] != null && dataRow["BCRP_TYPE"].ToString() == "固定值";
							if (flag3)
							{
								text += dataRow["BCRP_FIXEDCONTENT"].ToString();
							}
							bool flag4 = dataRow["BCRP_TIMEPARTFORMAT"] != null && dataRow["BCRP_TYPE"].ToString() == "时间";
							if (flag4)
							{
								string text2 = dataRow["BCRP_TIMEPARTFORMAT"].ToString();
								string text3 = dataRow["BCRP_TIMEPARTFORMAT"].ToString();
								List<TimeFormatCls> list = new List<TimeFormatCls>();
								bool flag5 = text2.Contains("DDD");
								if (flag5)
								{
									foreach (int charIndex in text2.GetAllIndexes("DDD"))
									{
										list.Add(new TimeFormatCls
										{
											strChar = "DDD",
											charIndex = charIndex
										});
									}
									text2 = text2.Replace("DDD", "###");
									text3 = text3.Replace("DDD", "");
								}
								bool flag6 = text2.Contains("D");
								if (flag6)
								{
									foreach (int charIndex2 in text2.GetAllIndexes("D"))
									{
										list.Add(new TimeFormatCls
										{
											strChar = "D",
											charIndex = charIndex2
										});
									}
									text2 = text2.Replace("D", "###");
									text3 = text3.Replace("D", "");
								}
								bool flag7 = text2.Contains("Z");
								if (flag7)
								{
									foreach (int charIndex3 in text2.GetAllIndexes("Z"))
									{
										list.Add(new TimeFormatCls
										{
											strChar = "Z",
											charIndex = charIndex3
										});
									}
									text2 = text2.Replace("Z", "#");
									text3 = text3.Replace("Z", "");
								}
								bool flag8 = text2.Contains("ww");
								if (flag8)
								{
									foreach (int charIndex4 in text2.GetAllIndexes("ww"))
									{
										list.Add(new TimeFormatCls
										{
											strChar = "ww",
											charIndex = charIndex4
										});
									}
									text2 = text2.Replace("ww", "##");
									text3 = text3.Replace("ww", "");
								}
								bool flag9 = text2.Contains("w");
								if (flag9)
								{
									foreach (int charIndex5 in text2.GetAllIndexes("w"))
									{
										list.Add(new TimeFormatCls
										{
											strChar = "w",
											charIndex = charIndex5
										});
									}
									text2 = text2.Replace("w", "#");
									text3 = text3.Replace("w", "");
								}
								DateTime sysDate = ClientUtils.GetSysDate();
								string text4 = "";
								bool flag10 = !string.IsNullOrWhiteSpace(text3);
								if (flag10)
								{
									text4 = sysDate.ToString(text3);
								}
								list.Sort();
								foreach (TimeFormatCls timeFormatCls in list)
								{
									bool flag11 = timeFormatCls.strChar == "DDD";
									if (flag11)
									{
										text4 = text4.Insert(timeFormatCls.charIndex, sysDate.DayOfYear.ToString().PadLeft(3, '0'));
									}
									bool flag12 = timeFormatCls.strChar == "D";
									if (flag12)
									{
										text4 = text4.Insert(timeFormatCls.charIndex, sysDate.DayOfYear.ToString());
									}
									bool flag13 = timeFormatCls.strChar == "Z";
									if (flag13)
									{
										text4 = text4.Insert(timeFormatCls.charIndex, Convert.ToInt32(sysDate.DayOfWeek).ToString());
									}
									bool flag14 = timeFormatCls.strChar == "ww";
									if (flag14)
									{
										GregorianCalendar gregorianCalendar = new GregorianCalendar();
										int weekOfYear = gregorianCalendar.GetWeekOfYear(sysDate, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
										text4 = text4.Insert(timeFormatCls.charIndex, weekOfYear.ToString().PadLeft(2, '0'));
									}
									bool flag15 = timeFormatCls.strChar == "w";
									if (flag15)
									{
										GregorianCalendar gregorianCalendar2 = new GregorianCalendar();
										int weekOfYear2 = gregorianCalendar2.GetWeekOfYear(sysDate, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
										text4 = text4.Insert(timeFormatCls.charIndex, weekOfYear2.ToString());
									}
								}
								bool flag16 = dataRow["BCRP_TIMEPARTCONVERT"] != null && !string.IsNullOrWhiteSpace(dataRow["BCRP_TIMEPARTCONVERT"].ToString());
								if (flag16)
								{
									string[] array = dataRow["BCRP_TIMEPARTCONVERT"].ToString().Trim().Replace('：', ':').Replace('；', ';').Split(new char[]
									{
										';'
									});
									foreach (string text5 in array)
									{
										string[] array3 = text5.Split(new char[]
										{
											':'
										});
										bool flag17 = array3.Length > 1;
										if (flag17)
										{
											text4 = text4.Replace(array3[0], array3[1]);
										}
									}
								}
								text += text4;
							}
							bool flag18 = dataRow["BCRP_TYPE"] != null && dataRow["BCRP_TYPE"].ToString() == "SQL函数取值";
							if (flag18)
							{
								bool flag19 = !string.IsNullOrWhiteSpace(dataRow["BCRP_SQLFUNCTIONNAME"].ToString());
								if (flag19)
								{
									string text6 = "";
									object[][] array4 = null;
									bool flag20 = !string.IsNullOrWhiteSpace(dataRow["BCRP_SQLFUNCTIONPARALIST"].ToString());
									if (flag20)
									{
										string text7 = dataRow["BCRP_SQLFUNCTIONPARALIST"].ToString();
										bool flag21 = text7.EndsWith(";");
										if (flag21)
										{
											text7 = text7.Remove(text7.Length - 1);
										}
										string[] array5 = text7.Split(new char[]
										{
											';'
										});
										array4 = new object[array5.Length][];
										for (int j = 0; j <= array5.Length - 1; j++)
										{
											for (int k = 0; k <= Params.Length - 1; k++)
											{
												bool flag22 = array5[j] == Params[k][2].ToString();
												if (flag22)
												{
													array4[j] = new object[]
													{
														ParameterDirection.Input,
														OracleType.VarChar,
														array5[j],
														Params[k][3].ToString()
													};
													text6 = string.Concat(new string[]
													{
														text6,
														text6,
														":",
														array5[j],
														","
													});
												}
											}
										}
										bool flag23 = text6.Length > 1 && text6.EndsWith(",");
										if (flag23)
										{
											text6 = "(" + text6.Remove(text6.Length - 1) + ")";
										}
									}
									DataSet dataSet2 = ClientUtils.ExecuteSQL("SELECT " + dataRow["BCRP_SQLFUNCTIONNAME"].ToString() + text6 + " FROM  DUAL", array4);
									bool flag24 = dataSet2.Tables.Count > 0 && dataSet2.Tables[0].Rows.Count > 0 && dataSet2.Tables[0].Rows[0][0] != null;
									if (flag24)
									{
										text += dataSet2.Tables[0].Rows[0][0].ToString();
									}
								}
							}
							bool flag25 = dataRow["BCRP_TYPE"] != null && dataRow["BCRP_TYPE"].ToString() == "传参";
							if (flag25)
							{
								bool flag26 = Params != null && Params.Length != 0;
								if (flag26)
								{
									for (int l = 0; l <= Params.Length - 1; l++)
									{
										bool flag27 = Params[l][2].ToString() == dataRow["BCRP_PARANAME"].ToString();
										if (flag27)
										{
											text += Params[l][3].ToString();
										}
									}
								}
							}
							bool flag28 = dataRow["BCRP_TYPE"] != null && dataRow["BCRP_TYPE"].ToString() == "流水号";
							if (flag28)
							{
								string text8 = "<ParaList>";
								bool flag29 = Params != null && Params.Length != 0;
								if (flag29)
								{
									for (int m = 0; m <= Params.Length - 1; m++)
									{
										text8 = string.Concat(new string[]
										{
											text8,
											"<",
											Params[m][2].ToString(),
											">",
											Params[m][3].ToString(),
											"</",
											Params[m][2].ToString(),
											">"
										});
									}
								}
								text8 += "</ParaList>";
								DataSet dataSet3 = ClientUtils.ExecuteProc("SAJET.GetSquenceNextValueByID", new object[][]
								{
									new object[]
									{
										ParameterDirection.Input,
										OracleType.VarChar,
										"IBARCODE_UNIQUEID",
										StrBarcodeUniqueID
									},
									new object[]
									{
										ParameterDirection.Input,
										OracleType.VarChar,
										"IBARCODERULE_ID",
										dataRow["BARCODERULE_ID"].ToString()
									},
									new object[]
									{
										ParameterDirection.Input,
										OracleType.VarChar,
										"IBCRP_ID",
										dataRow["BCRP_ID"].ToString()
									},
									new object[]
									{
										ParameterDirection.Input,
										OracleType.VarChar,
										"ISQUENCE_RESETPARALIST",
										text8
									},
									new object[]
									{
										ParameterDirection.Input,
										OracleType.Int32,
										"ISTATE",
										state
									},
									new object[]
									{
										ParameterDirection.Output,
										OracleType.Int32,
										"ISQUENCE_CURRENTVALUE",
										0
									},
									new object[]
									{
										ParameterDirection.Output,
										OracleType.VarChar,
										"O_RES",
										"N/A"
									}
								});
								string a = dataSet3.Tables[0].Rows[0]["O_RES"].ToString();
								bool flag30 = a == "OK";
								if (flag30)
								{
									string text9 = dataSet3.Tables[0].Rows[0]["ISQUENCE_CURRENTVALUE"].ToString();
									bool flag31 = dataRow["BCRP_SQUENCEFORMAT"].ToString() == "十六进制";
									if (flag31)
									{
										text9 = Convert.ToString(Convert.ToInt32(text9), 16).ToUpper();
									}
									bool flag32 = text9.Length > Convert.ToInt32(dataRow["BCRP_SQUENCELENGTH"]);
									if (flag32)
									{
										string text10 = text9.Substring(0, text9.Length - Convert.ToInt32(dataRow["BCRP_SQUENCELENGTH"]) + 1);
										bool flag33 = dataRow["BCRP_SQUENCEOVERFLOWCHAR"] != null && !string.IsNullOrWhiteSpace(dataRow["BCRP_SQUENCEOVERFLOWCHAR"].ToString());
										if (flag33)
										{
											string[] array6 = dataRow["BCRP_SQUENCEOVERFLOWCHAR"].ToString().Trim().Replace('：', ':').Replace('；', ';').Split(new char[]
											{
												';'
											});
											foreach (string text11 in array6)
											{
												string[] array8 = text11.Split(new char[]
												{
													':'
												});
												bool flag34 = array8.Length > 1;
												if (flag34)
												{
													text10 = text10.Replace(array8[0], array8[1]);
												}
											}
											text9 = text10 + text9.Substring(text9.Length - Convert.ToInt32(dataRow["BCRP_SQUENCELENGTH"]) + 1);
										}
										else
										{
											text9 = text9.Substring(text9.Length - Convert.ToInt32(dataRow["BCRP_SQUENCELENGTH"]), Convert.ToInt32(dataRow["BCRP_SQUENCELENGTH"]));
										}
									}
									string text12 = "";
									while (text12.Length + text9.Length <= Convert.ToInt32(dataRow["BCRP_SQUENCELENGTH"]))
									{
										bool flag35 = dataRow["BCRP_SQUENCEMAKEUPCHAR"] != null && !string.IsNullOrWhiteSpace(dataRow["BCRP_SQUENCEMAKEUPCHAR"].ToString());
										if (flag35)
										{
											text12 += dataRow["BCRP_SQUENCEMAKEUPCHAR"].ToString();
										}
										else
										{
											text12 += "0";
										}
									}
									text9 = text12.Substring(0, Convert.ToInt32(dataRow["BCRP_SQUENCELENGTH"]) - text9.Length) + text9;
									text += text9;
								}
							}
						}
						result = text;
					}
					else
					{
						result = "";
					}
				}
			}
			catch (Exception ex)
			{
				SajetCommon.Show_Message(ex.Message, 0);
				result = "";
			}
			return result;
		}

		// Token: 0x06000028 RID: 40 RVA: 0x00009E44 File Offset: 0x00008044
		public static string SetLanguage(string sSearchText, string sDefaultTxt, int iTransType)
		{
			string text = SajetCommon.SetLanguage(sSearchText, iTransType);
			bool flag = text != sSearchText;
			string result;
			if (flag)
			{
				result = text;
			}
			else
			{
				result = sDefaultTxt;
			}
			return result;
		}

		// Token: 0x06000029 RID: 41 RVA: 0x00009E70 File Offset: 0x00008070
		public static string SetLanguage(string sSearchText)
		{
			string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(SajetCommon.g_sFileName);
			string text = ClientUtils.SetLanguage(sSearchText, SajetCommon.g_sExeName, fileNameWithoutExtension);
			bool flag = sSearchText == text;
			if (flag)
			{
				fileNameWithoutExtension = SajetCommon.g_sExeName;
				text = ClientUtils.SetLanguage(sSearchText, SajetCommon.g_sExeName, fileNameWithoutExtension);
			}
			return text;
		}

		// Token: 0x0600002A RID: 42 RVA: 0x00009EC8 File Offset: 0x000080C8
		public static string SetLanguage(string sSearchText, int iTransType)
		{
			string xmlFileName = "";
			if (iTransType != 1)
			{
				if (iTransType == 2)
				{
					xmlFileName = SajetCommon.g_sExeName;
				}
			}
			else
			{
				xmlFileName = Path.GetFileNameWithoutExtension(SajetCommon.g_sFileName);
			}
			return ClientUtils.SetLanguage(sSearchText, SajetCommon.g_sExeName, xmlFileName);
		}

		// Token: 0x0600002B RID: 43 RVA: 0x00009F18 File Offset: 0x00008118
		public static void SetLanguageControl(Control c)
		{
			string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(SajetCommon.g_sFileName);
			ClientUtils.SetLanguage(c, SajetCommon.g_sExeName, fileNameWithoutExtension);
			ClientUtils.SetLanguage(c, SajetCommon.g_sExeName, SajetCommon.g_sExeName);
		}

		// Token: 0x0600002C RID: 44 RVA: 0x00009F50 File Offset: 0x00008150
		public static string GetSysBaseData(string sProgram, string sParamName, ref string sErrorMsg)
		{
			string sSQL = string.Concat(new string[]
			{
				" SELECT PARAM_VALUE    FROM SAJET.SYS_BASE   WHERE Upper(PROGRAM) = '",
				sProgram.ToUpper(),
				"'     and Upper(PARAM_NAME) = '",
				sParamName.ToUpper(),
				"' "
			});
			DataSet dataSet = ClientUtils.ExecuteSQL(sSQL);
			bool flag = dataSet.Tables[0].Rows.Count > 0;
			string result;
			if (flag)
			{
				result = dataSet.Tables[0].Rows[0]["PARAM_VALUE"].ToString();
			}
			else
			{
				sErrorMsg = sErrorMsg + sParamName + Environment.NewLine;
				result = "";
			}
			return result;
		}

		// Token: 0x0600002D RID: 45 RVA: 0x0000A000 File Offset: 0x00008200
		public static string GetMaxID(string sTable, string sField, int iIDLength)
		{
			string result = "0";
			try
			{
				DataSet dataSet = ClientUtils.ExecuteProc("SAJET.SJ_GET_MAXID", new object[][]
				{
					new object[]
					{
						ParameterDirection.Input,
						OracleType.VarChar,
						"TFIELD",
						sField
					},
					new object[]
					{
						ParameterDirection.Input,
						OracleType.VarChar,
						"TTABLE",
						sTable
					},
					new object[]
					{
						ParameterDirection.Input,
						OracleType.VarChar,
						"TNUM",
						iIDLength.ToString()
					},
					new object[]
					{
						ParameterDirection.Output,
						OracleType.VarChar,
						"TRES",
						""
					},
					new object[]
					{
						ParameterDirection.Output,
						OracleType.VarChar,
						"T_MAXID",
						""
					}
				});
				string text = dataSet.Tables[0].Rows[0]["TRES"].ToString();
				result = dataSet.Tables[0].Rows[0]["T_MAXID"].ToString();
				bool flag = text != "OK";
				if (flag)
				{
					SajetCommon.Show_Message(text, 0);
					return "0";
				}
			}
			catch (Exception ex)
			{
				SajetCommon.Show_Message("SAJET.SJ_GET_MAXID" + Environment.NewLine + ex.Message, 0);
				return "0";
			}
			return result;
		}

		// Token: 0x0600002E RID: 46 RVA: 0x0000A1C0 File Offset: 0x000083C0
		public static string GetID(string sTable, string sFieldID, string sFieldName, string sValue)
		{
			return SajetCommon.GetID(sTable, sFieldID, sFieldName, sValue, "");
		}

		// Token: 0x0600002F RID: 47 RVA: 0x0000A1E0 File Offset: 0x000083E0
		public static string GetID(string sTable, string sFieldID, string sFieldName, string sValue, string sEnabled)
		{
			bool flag = string.IsNullOrEmpty(sValue);
			string result;
			if (flag)
			{
				result = "0";
			}
			else
			{
				string text = string.Concat(new string[]
				{
					"select ",
					sFieldID,
					" from ",
					sTable,
					" where ",
					sFieldName,
					" = '",
					sValue,
					"' "
				});
				bool flag2 = !string.IsNullOrEmpty(sEnabled);
				if (flag2)
				{
					text = text + " and ENABLED = '" + sEnabled + "' ";
				}
				text += " and Rownum = 1 ";
				DataSet dataSet = ClientUtils.ExecuteSQL(text);
				bool flag3 = dataSet.Tables[0].Rows.Count > 0;
				if (flag3)
				{
					result = dataSet.Tables[0].Rows[0][sFieldID].ToString();
				}
				else
				{
					result = "0";
				}
			}
			return result;
		}

		// Token: 0x06000030 RID: 48 RVA: 0x0000A2CC File Offset: 0x000084CC
		public static Image LoadImage(string sFileName)
		{
			string str = Application.StartupPath + "\\";
			bool flag = File.Exists(str + sFileName);
			Image result;
			if (flag)
			{
				result = Image.FromFile(str + sFileName);
			}
			else
			{
				result = null;
			}
			return result;
		}

		// Token: 0x0400005E RID: 94
		public static string g_sFileVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion.ToString();

		// Token: 0x0400005F RID: 95
		public static string g_sFileName = Path.GetFileName(FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileName);

		// Token: 0x04000060 RID: 96
		public static string g_sExeName = ClientUtils.fCurrentProject;
	}
}
